<?php

namespace Admin\Controller;

class StoreController extends AdminbaseController {

    function _initialize() {
        parent::_initialize();
        $this->currentModel = D("Store");
    }

    //首页
    public function index() {
        $requestMap = $this->convertRequestToMap();
        $users_obj= M("admin");
        $userId=$_SESSION['ADMIN_ID'];
        $user=$users_obj->where("user_id=$userId")->find();
        $requestMap["s.enterprise_code"] = $user["enterprise_code"];
        //分页
        $count = $this->currentModel->getListCount($requestMap);
        $page = $this->page($count, C("DEFAULT_PAGE_SIZE"));

        //获取列表
        $list = $this->currentModel->queryForList($page, $requestMap);

//        $this->assign("statusEnum", C("DEFAULT_YN"));
        $this->assign('list', $list);

        $this->assign("page", $page->show('Admin', $this->parameter));
        $this->display();

    }
    public function remove() {

        $id = $_REQUEST['id'];
        $this->currentModel->deleteById($id);

        $this->success('删除成功!', U("Store/index"));

    }

    public function add() {
        $this->display("add");
    }

    /**
     * 添加数据
     */
    public function addPost() {

        $users_obj= M("admin");
        $userId=$_SESSION['ADMIN_ID'];
        $user=$users_obj->where("user_id=$userId")->find();
        $data["enterprise_code"] = $user["enterprise_code"];
        $data["update_id"] = $user["employee_id"];

        $data["store_code"] = $_REQUEST["store_code"];
        $data["store_name"] = $_REQUEST["store_name"];
        $data["remark"] = $_REQUEST["remark"];
        $data["create_time"] = getCurrentDate();
        $data["update_time"] = getCurrentDate();

        $this->currentModel->add($data);

        $this->success("添加成功", U("Store/index"));

    }

    public function edit() {
        $id = $_REQUEST["id"];
        $info = D("Store")->queryById($id);
        $this->assign("info", $info);
        $this->display("edit");
    }
    /**
     * 更新数据
     */
    public function editPost() {

        $id = $_REQUEST["id"];
        $data = $this->currentModel->queryById($id);
        $users_obj= M("admin");
        $userId=$_SESSION['ADMIN_ID'];
        $user=$users_obj->where("user_id=$userId")->find();
        $data["enterprise_code"] = $user["enterprise_code"];
        $data["update_id"] = $user["employee_id"];

        $data["store_code"] = $_REQUEST["store_code"];
        $data["store_name"] = $_REQUEST["store_name"];
        $data["remark"] = $_REQUEST["remark"];
        $data["update_time"] = getCurrentDate();

        $this->currentModel->updateInfo($data);

        $this->success("更新成功", U("Store/index"));

    }
}